package com.ll;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@Slf4j
public class CountRateLimiterDemo {
   
    private  static AtomicInteger count = new AtomicInteger(1);

    public static void exec() {  
        if (count.get() >= 5) {  
            System.out.println("请求用户过多，请稍后在试！"+System.currentTimeMillis()/1000);  
        } else {  
            count.incrementAndGet();  
            try {  
                //处理核心逻辑  
                TimeUnit.SECONDS.sleep(1);
                System.out.println("--"+System.currentTimeMillis()/1000);  
            } catch (InterruptedException e) {  
                e.printStackTrace();  
            } finally {  
                count.decrementAndGet();  
            }  
        }  
    }

    @Test
    public void test(){
//        List<Integer> a = new ArrayList<>();
//        for(int i=1; i<10; i ++){
//        a.add(i);
//        }
//appId=bfb5ccdf8f6347cd8512ab6cc25610d2&appSecret=2538afdf12f4d487f38785cbdce9c1fe&dingUserId=003110&endDate=1609430400000&startDate=1635264000000
//appId=bfb5ccdf8f6347cd8512ab6cc25610d2&appSecret=2538afdf12f4d487f38785cbdce9c1fe&dingUserId=003110&endDate=1635264000000&startDate=1609430400000
//        log.info(" aa : {} ",a);
//        String md5String = MD5Utils.getInstance().getMD5String("appId=bfb5ccdf8f6347cd8512ab6cc25610d2&appSecret=2538afdf12f4d487f38785cbdce9c1fe&dingUserId=003110&endDate=1635264000000&startDate=1609430400000");
//        System.out.println(md5String);

        List<String> list = new ArrayList<>();
        list.add("123");
        list.add("456");
        list.add("789");
        System.out.println(list.toString());
        System.out.println(JSONObject.toJSON(list));
    }
}  